/**
 * @description 设置sessionStorage 或 localStorage
 * @author tanjunxin@lvshou.com
 * @param {String} key Storage名称
 * @param {String} value Storage值
 * @param {String} type 存储Storage方式
 */


const getToken = (type = 'local') => {
  try {
    return type == 'local' ?  localStorage.getItem(TokenKey):sessionStorage.getItem(TokenKey)
  } catch (error) {
    console.log(error)
  }
}

const removeToken = (type = 'local') => {
  type == 'local' ? localStorage.removeItem(TokenKey):sessionStorage.removeItem(TokenKey)
}

const setStorage = (key, value, type = 'local') => {
  type == 'local' ? localStorage.setItem(key, JSON.stringify(value)):sessionStorage.setItem(key, JSON.stringify(value))
}

const getStorage = (key, type = 'local') => {
  try {
    return type == 'local' ? JSON.parse(localStorage.getItem(key)):JSON.parse(sessionStorage.getItem(key))
  } catch (error) {
    console.log(error)
  }
}

const removeStorage = (key, type = 'local') => {
  type == 'local' ? localStorage.removeItem(key):sessionStorage.removeItem(key)
}

export { getToken, removeToken, setStorage, getStorage, removeStorage }
